package com.gitee.wsl.struct.table.mini.dsl

import com.gitee.wsl.struct.table.mini.CellStyle
import com.gitee.wsl.struct.table.mini.TextAlignment
import kotlin.DeprecationLevel.ERROR
import kotlin.jvm.JvmSynthetic


@PicnicDsl
interface CellStyleDsl {
    var paddingLeft: Int?
    var paddingRight: Int?
    var paddingTop: Int?
    var paddingBottom: Int?

    var borderLeft: Boolean?
    var borderRight: Boolean?
    var borderTop: Boolean?
    var borderBottom: Boolean?

    var alignment: TextAlignment?

    var border: Boolean
        @JvmSynthetic
        @Deprecated("Use individual getters", level = ERROR)
        get() = throw UnsupportedOperationException()
        set(value) {
            borderLeft = value
            borderRight = value
            borderTop = value
            borderBottom = value
        }

    var padding: Int
        @JvmSynthetic
        @Deprecated("Use individual getters", level = ERROR)
        get() = throw UnsupportedOperationException()
        set(value) {
            paddingLeft = value
            paddingRight = value
            paddingTop = value
            paddingBottom = value
        }
}

internal class CellStyleDslImpl : CellStyleDsl {
    override var paddingLeft: Int? = null
    override var paddingRight: Int? = null
    override var paddingTop: Int? = null
    override var paddingBottom: Int? = null
    override var borderLeft: Boolean? = null
    override var borderRight: Boolean? = null
    override var borderTop: Boolean? = null
    override var borderBottom: Boolean? = null
    override var alignment: TextAlignment? = null

    fun createOrNull(): CellStyle? {
        if (paddingLeft != null ||
            paddingRight != null ||
            paddingTop != null ||
            paddingBottom != null ||
            borderLeft != null ||
            borderRight != null ||
            borderTop != null ||
            borderBottom != null ||
            alignment != null
        ) {
            return CellStyle {
                paddingLeft = this@CellStyleDslImpl.paddingLeft
                paddingRight = this@CellStyleDslImpl.paddingRight
                paddingTop = this@CellStyleDslImpl.paddingTop
                paddingBottom = this@CellStyleDslImpl.paddingBottom
                borderLeft = this@CellStyleDslImpl.borderLeft
                borderRight = this@CellStyleDslImpl.borderRight
                borderTop = this@CellStyleDslImpl.borderTop
                borderBottom = this@CellStyleDslImpl.borderBottom
                alignment = this@CellStyleDslImpl.alignment
            }
        }
        return null
    }
}
